#include<iostream>
using namespace std;
#include<unistd.h>
#include<sys/types.h>


//创建一个新的会话
int main(){

    pid_t id = fork();
    if(id == 0){
        //子进程
        printf("child process PID is %d\n",getpid());
        printf("child process GID is %d\n",getpgid(0));//获取进程组的id
        printf("child process SID is %d\n",getsid(0));//获取会话组的id

        sleep(5);
        setsid();//让子进程去创建一个会话组，这个时候，子进程即是会话组的组长，也是进程组的组长
        printf("sid change\n");

        printf("child process PID is %d\n",getpid());
        printf("child process GID is %d\n",getpgid(0));//获取进程组的id
        printf("child process SID is %d\n",getsid(0));//获取会话组的id
        sleep(10);
        exit(0);


    }
    //父亲进程,由于不能使用父亲进程创建会话，那么我们直接让父亲进程退出
    return 0;
}